#define _CRT_SECURE_NO_WARNINGS	


typedef struct {
    int* arr;
    int front;
    int end;
    int capacity;
} MyCircularQueue;

MyCircularQueue* myCircularQueueCreate(int k) {
    MyCircularQueue* cq = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));
    cq->arr = (int*)malloc((k + 1) * sizeof(int));
    cq->front = cq->end = 0;
    cq->capacity = k;
    return cq;
}

bool myCircularQueueIsEmpty(MyCircularQueue* obj) {
    return obj->front == obj->end;
}

bool myCircularQueueIsFull(MyCircularQueue* obj) {
    return (obj->end + 1) % (obj->capacity + 1) == obj->front;
}

bool myCircularQueueEnQueue(MyCircularQueue* obj, int value) {
    if (myCircularQueueIsFull(obj))
        return false;
    obj->arr[obj->end++] = value;
    obj->end %= obj->capacity + 1;
    return true;
}

bool myCircularQueueDeQueue(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
        return false;
    obj->front++;
    obj->front %= obj->capacity + 1;
    return true;
}

int myCircularQueueFront(MyCircularQueue* obj) {
    int ret = myCircularQueueIsEmpty(obj) ? -1 : obj->arr[obj->front];
    return ret;
}

int myCircularQueueRear(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
        return -1;
    int prev = obj->end - 1;
    if (obj->end == 0)
        prev = obj->capacity;
    return obj->arr[prev];
}


void myCircularQueueFree(MyCircularQueue* obj) {
    if (obj->arr)
        free(obj->arr);
    obj->capacity = obj->front = obj->end = 0;
    free(obj);
    obj = NULL;
}

/**
 * Your MyCircularQueue struct will be instantiated and called as such:
 * MyCircularQueue* obj = myCircularQueueCreate(k);
 * bool param_1 = myCircularQueueEnQueue(obj, value);

 * bool param_2 = myCircularQueueDeQueue(obj);

 * int param_3 = myCircularQueueFront(obj);

 * int param_4 = myCircularQueueRear(obj);

 * bool param_5 = myCircularQueueIsEmpty(obj);

 * bool param_6 = myCircularQueueIsFull(obj);

 * myCircularQueueFree(obj);
*/